package uml.view.factory;

import java.awt.Polygon;

import uml.eventsystem.events.UMLEventId;
import uml.objects.AnchorPoint;
import uml.objects.ArrowEnd;
import uml.objects.RelationshipArrow;
import uml.objects.UMLObject;
import uml.util.UMLConstants;

/**
 * A factory class that creates UML relationship objects. The methods of this 
 * class return formatted base <tt>RelationshipArrow</tt> objects 
 * that represent different UML relationships. 
 * 
 * @author Neil Obetz
 *
 */

public final class RelationshipArrowFactory
{
	/**
	 * Creates and formats an association
	 * @return 
	 * 
	 * @return the association object
	 */
	
	/**
	 * A filter method for users to invoke when a
	 * UMLObject creation event is invoked  
	 * 
	 * @param eventId the event that occurred
	 * @return the object requested
	 */
	
	public static UMLObject createObject (UMLEventId eventId)
	{
		UMLObject obj = new UMLObject ();
		
		if (eventId.equals (UMLEventId.MAKE_ASSOCIATION))
		{
			obj = createAssociation ();
		}
		else if (eventId.equals (UMLEventId.MAKE_COMPOSITION))
		{
			obj = createComposition ();
		}
		else if (eventId.equals (UMLEventId.MAKE_AGGREGATION))
		{
			obj = createAggregation ();
		}
		else if (eventId.equals (UMLEventId.MAKE_GENERALIZATION))
		{
			obj = createGeneralization ();
		}
		else
		{
			System.out.println ("Not a valid id. Returning a default value.");
		}
		
		return obj;
	}
	
	public static RelationshipArrow createAssociation ()
	{
		RelationshipArrow relationship = new RelationshipArrow ();
		return (relationship);
	}
	
	/**'
	 * Creates and formats a composition
	 * 
	 * @return the composition object
	 */
	
	public static RelationshipArrow createComposition ()
	{
		RelationshipArrow composition = new RelationshipArrow ();
		return (composition);
	}
	
	/**
	 * Creates and formats an aggregation.
	 * 
	 * @return the aggregation object
	 */
	
	public static RelationshipArrow createAggregation ()
	{
		RelationshipArrow aggregation = new RelationshipArrow ();
		aggregation.setTail (createAggregateEnd ());
		return (aggregation);
	}
	
	/**
	 * Creates and formats the generalization.
	 * 
	 * @return the generalization
	 */
	
	public static RelationshipArrow createGeneralization ()
	{
		RelationshipArrow composition = new RelationshipArrow ();
		return (composition);
	}
	
	/**
	 * Creates an <tt>ArrowEnd</tt> formatted to look like 
	 * the head of an aggregate relationship.
	 * 
	 * @return the aggregate arrow head
	 */
	
	public static ArrowEnd createAggregateEnd ()
	{
		ArrowEnd aggregateEnd = new ArrowEnd ();
		
		aggregateEnd.setEndType (UMLConstants.DIAMOND_ARROW_END);
		aggregateEnd.setColor (UMLConstants.AGGREGATE_HEAD);
		
		return aggregateEnd;
	}
}
